//package com.powerunion.datacollection.persistence.db.jdbc.operator;
//
//import java.util.Iterator;
//import java.util.List;
//import java.util.Map;
//import java.util.Set;
//
//import com.powerunion.datacollection.util.cache.ICache;
//import com.powerunion.datacollection.util.cache.StrongCache;
//
//final public class TableOperator implements ITableAccess {
////	private static ICache SQL_CACHER = new StrongCache(1024);
////	private String dataSourceName;
////	private String tableName;
////	private Set filedSet;
////	private Class valueObjectClass;
////	private boolean autoGenerateKey = false; // 是否拥有自动增量的key
////	private String autoKeyFiledName;
////	private String primaryKeyName;
////
////	// private static SysLogger logger =
////	// SysLogger.getSysLogerInstance(TableOperator.class.
////	// getName());
////	/**
////	 * TableOperator（默认为此表的主键为非自动增量）
////	 * 
////	 * @param dataSourceName
////	 *            数据源名称
////	 * @param tableName
////	 *            数据库表名称
////	 * @param valueObjectClass
////	 *            表对应的值对象
////	 */
////	public TableOperator(String dataSourceName, String tableName,
////			Class valueObjectClass) {
////		this.dataSourceName = dataSourceName;
////		this.tableName = tableName;
////		this.valueObjectClass = valueObjectClass;
////		this.autoGenerateKey = false;
////		filedSet = (Set) SQL_CACHER.get(this.tableName);
////		primaryKeyName = (String) SQL_CACHER.get(this.tableName + "_pk");
////		if (filedSet == null || primaryKeyName == null) {
////			try {
////				filedSet = DBHelper.getTableFields(tableName, ConnectionFactory
////						.getConncetion(this.dataSourceName));
////				SQL_CACHER.put(this.tableName, filedSet);
////				this.primaryKeyName = DBHelper.getTablePrimaryKeyFieldName(
////						tableName, ConnectionFactory
////								.getConncetion(this.dataSourceName));
////				SQL_CACHER.put(this.tableName + "_pk", this.primaryKeyName);
////				logger.debug("inited!");
////			} catch (Exception ex) {
////				logger.error(ex);
////				throw new AppRuntimeException(ex);
////			}
////		}
////	}
////
////	/**
////	 * TableOperator
////	 * 
////	 * @param dataSourceName
////	 *            数据源名称
////	 * @param tableName
////	 *            数据库表名称
////	 * @param valueObjectClass
////	 *            表对应的值对象
////	 * @param autoKeyFiledName
////	 *            自动增量的key的字段名称
////	 */
////
////	public TableOperator(String dataSourceName, String tableName,
////			Class valueObjectClass, String autoKeyFiledName) {
////		this(dataSourceName, tableName, valueObjectClass);
////		if (autoKeyFiledName != null) {
////			if (!autoKeyFiledName.equals("")) {
////				this.autoGenerateKey = true;
////				this.autoKeyFiledName = autoKeyFiledName;
////			}
////		}
////	}
////
////	/**
////	 * TableOperator
////	 * 
////	 * @param dataSourceName
////	 *            数据源名称
////	 * @param tableName
////	 *            数据库表名称
////	 * @param valueObjectClass
////	 *            表对应的值对象
////	 * @param autoKeyFlag
////	 *            此表的主键是否为自动增量的
////	 */
////	public TableOperator(String dataSourceName, String tableName,
////			Class valueObjectClass, boolean autoKeyFlag) {
////		this(dataSourceName, tableName, valueObjectClass);
////		this.autoGenerateKey = autoKeyFlag;
////		this.autoKeyFiledName = primaryKeyName;
////	}
////
////	/**
////	 * 根据主键查找记录
////	 * 
////	 * @param pk
////	 *            Object
////	 * @return 返回此记录的表值对象
////	 * @throws DBOperatorException
////	 */
////	public Object selectByPrimaryKey(Object pk) throws DBOperatorException {
////		Object o = null;
////		if (this.primaryKeyName == null) {
////			throw new com.beetle.framework.AppRuntimeException(
////					"此表没有定义主键或为组合主键，不支持此方法");
////		}
////		QueryOperator query = new QueryOperator();
////		query.setDataSourceName(this.dataSourceName);
////		query.setSql(SqlGenerator.generateSelectByPKSql(this.filedSet,
////				this.tableName, this.primaryKeyName));
////		query.addParameter(pk);
////		try {
////			query.access();
////			if (query.resultSetAvailable()) {
////				RsDataSet rs = new RsDataSet(query.getSqlResultSet());
////				o = rowToObj(rs);
////			}
////			return o;
////		} catch (DBOperatorException ex) {
////			throw new DBOperatorException(ex);
////		}
////	}
////
////	private Object rowToObj(RsDataSet rs) throws AppRuntimeException {
////		Object o = null;
////		try {
////			o = valueObjectClass.newInstance();
////		} catch (Exception ex) {
////			throw new AppRuntimeException("没法实例化对象", ex);
////		}
////		Iterator it = this.filedSet.iterator();
////		while (it.hasNext()) {
////			String key = (String) it.next();
////			Object value = rs.getFieldValue(key);
////			if (value == null) {
////				continue;
////			}
////			ObjectUtil.setValue(key, o, value);
////		}
////		return o;
////	}
////
////	/*
////	 * private Object rowToObj(RsDataSet rs) throws AppRuntimeException { Object
////	 * o = null; try { o = valueObjectClass.newInstance(); } catch (Exception
////	 * ex) { throw new AppRuntimeException("没法实例化对象", ex); } BeanUtilsBean bu =
////	 * BeanUtilsBean.getInstance(); Iterator it = this.filedSet.iterator();
////	 * while (it.hasNext()) { String key = (String) it.next(); Object value =
////	 * rs.getFieldValue(key); try { if (value == null) { continue; }
////	 * bu.copyProperty(o, key, value); } catch (Exception ex1) { throw new
////	 * AppRuntimeException("对此对象装配解析出现问题,请检查对象属性是否和数据库字段一致", ex1); } } return o;
////	 * }
////	 */
////	/**
////	 * 根据条件查找
////	 * 
////	 * @param whereStr
////	 *            sql语句where条件子语句
////	 * @param values
////	 *            where语句参数值，按参数顺序填充数组
////	 * @return 查询结果值对象列表 如果记录数为1时，通过list.get(0)获取
////	 * @throws DBOperatorException
////	 */
////	public List selectByWhereCondition(String whereStr, Object values[])
////			throws DBOperatorException {
////		List rd = new ArrayList();
////		QueryOperator query = new QueryOperator();
////		query.setDataSourceName(this.dataSourceName);
////		query.setSql(SqlGenerator.generateSelectAllSql(this.filedSet,
////				this.tableName)
////				+ whereStr);
////		int i = whereStr.indexOf("?");
////		if (i > 0) {
////			for (int j = 0; j < values.length; j++) {
////				query.addParameter(values[j]);
////			}
////		}
////		try {
////			query.access();
////			if (query.resultSetAvailable()) {
////				RsDataSet rs = new RsDataSet(query.getSqlResultSet());
////				for (int ii = 0; ii < rs.rowCount; ii++) {
////					Object o = rowToObj(rs);
////					rd.add(o);
////					rs.next();
////				}
////				rs.clearAll();
////			}
////			return rd;
////		} catch (DBOperatorException ex) {
////			throw new DBOperatorException(ex);
////		}
////	}
////
////	/**
////	 * 插入一条记录
////	 * 
////	 * @param valueObject
////	 *            表的值对象
////	 * @return 操作影响条数
////	 * @throws DBOperatorException
////	 */
////	public int insert(Object valueObject) throws DBOperatorException {
////		Map valueMap = objToMap(valueObject, this.filedSet);
////		UpdateOperator update = new UpdateOperator();
////		update.setDataSourceName(this.dataSourceName);
////		update.setSql(SqlGenerator.generateInsertSql(this.filedSet,
////				this.tableName, this.autoGenerateKey, this.autoKeyFiledName));
////		Iterator it = this.filedSet.iterator();
////		while (it.hasNext()) {
////			Object key = it.next();
////			if (autoGenerateKey) {
////				if (key.equals(autoKeyFiledName)) {
////					continue;
////				}
////			}
////			addUpdateParams(valueMap, update, key);
////		}
////		try {
////			update.access();
////			return update.getEffectCounts();
////		} catch (DBOperatorException ex) {
////			throw new DBOperatorException(ex);
////		} finally {
////			valueMap.clear();
////		}
////	}
////
////	private void addUpdateParams(Map valueMap, UpdateOperator update, Object key) {
////		ValueInfo vi = (ValueInfo) valueMap.get(key);
////		if (vi.getValue() != null) {
////			update.addParameter(vi.getValue());
////		} else {
////			Class type = vi.getType();
////			if (type.equals(Integer.class)) {
////				update.addParameter(new SqlParameter(SqlType.INTEGER, null));
////			} else if (type.equals(String.class)) {
////				update.addParameter(new SqlParameter(SqlType.VARCHAR, null));
////			} else if (type.equals(Long.class)) {
////				update.addParameter(new SqlParameter(SqlType.BIGINT, null));
////			} else if (type.equals(java.sql.Timestamp.class)) {
////				update.addParameter(new SqlParameter(SqlType.TIMESTAMP, null));
////			} else if (type.equals(java.sql.Time.class)) {
////				update.addParameter(new SqlParameter(SqlType.TIME, null));
////			} else if (type.equals(Double.class)) {
////				update.addParameter(new SqlParameter(SqlType.DOUBLE, null));
////			} else if (type.equals(java.sql.Date.class)) {
////				update.addParameter(new SqlParameter(SqlType.DATE, null));
////			} else { // ...
////				// System.out.println("-----"+key);
////				update.addParameter(new SqlParameter(SqlType.NUMERIC, null));
////			}
////		}
////	}
////
////	private class ValueInfo {
////		private Object value;
////		private Class type;
////
////		public ValueInfo(Object value, Class type) {
////			this.value = value;
////			this.type = type;
////		}
////
////		public Object getValue() {
////			return value;
////		}
////
////		public Class getType() {
////			return type;
////		}
////	}
////
////	private Map objToMap(Object obj, Set fields) {
////		Map map = new HashMap();
////		Iterator it = fields.iterator();
////		while (it.hasNext()) {
////			String fn = (String) it.next();
////			Class type = ObjectUtil.getType(fn, obj);
////			Object value = ObjectUtil.getValue(fn, obj);
////			if (value != null) {
////				map.put(fn, new ValueInfo(value, type));
////			}
////		}
////		return map;
////	}
////
////	/*
////	 * private Map objToMap(Object obj, Set fields) { Map map = new HashMap();
////	 * BeanUtilsBean bub = BeanUtilsBean.getInstance(); PropertyUtilsBean pup =
////	 * bub.getPropertyUtils(); PropertyDescriptor dt[] =
////	 * pup.getPropertyDescriptors(obj); for (int i = 0; i < dt.length; i++) {
////	 * String name = dt[i].getName(); Class type = dt[i].getPropertyType(); try
////	 * { Object value = pup.getProperty(obj, name); Iterator it =
////	 * fields.iterator(); while (it.hasNext()) { String fn = (String) it.next();
////	 * if (fn.equals(name)) { map.put(fn, new ValueInfo(value, type)); break; }
////	 * } } catch (Exception e) { throw new
////	 * com.beetle.framework.AppRuntimeException("对此对象解析出现问题，不支持", e); } } return
////	 * map; }
////	 */
////	/**
////	 * 批量插入记录
////	 * 
////	 * @param valueObjectList
////	 *            List
////	 * @return int[]
////	 * @throws DBOperatorException
////	 */
////	public int[] insertBatch(List valueObjectList) throws DBOperatorException {
////		UpdateOperator update = new UpdateOperator();
////		update.setDataSourceName(this.dataSourceName);
////		update.setSql(SqlGenerator.generateInsertSql(this.filedSet,
////				this.tableName, this.autoGenerateKey, this.autoKeyFiledName));
////		for (int i = 0; i < valueObjectList.size(); i++) {
////			Object valueObject = valueObjectList.get(i);
////			SqlParameterSet r = new SqlParameterSet();
////			Map valueMap = objToMap(valueObject, this.filedSet);
////			Iterator it = this.filedSet.iterator();
////			while (it.hasNext()) {
////				Object key = it.next();
////				if (autoGenerateKey) {
////					if (key.equals(autoKeyFiledName)) {
////						continue;
////					}
////				}
////				addBatchParams(r, valueMap, key);
////			}
////			update.addBatchParameter(r); //
////			valueMap.clear();
////		}
////		try {
////			update.access();
////			return update.getBatchEffectCounts();
////		} catch (DBOperatorException ex) {
////			throw new DBOperatorException(ex);
////		} finally {
////			// valueObjectList.clear();
////		}
////	}
////
////	private void addBatchParams(SqlParameterSet r, Map valueMap, Object key) {
////		ValueInfo vi = (ValueInfo) valueMap.get(key);
////		if (vi.getValue() != null) {
////			r.addParameter(vi.getValue());
////		} else {
////			Class type = vi.getType();
////			if (type.equals(Integer.class)) {
////				r.addParameter(new SqlParameter(SqlType.INTEGER, null));
////			} else if (type.equals(String.class)) {
////				r.addParameter(new SqlParameter(SqlType.VARCHAR, null));
////			} else if (type.equals(Long.class)) {
////				r.addParameter(new SqlParameter(SqlType.BIGINT, null));
////			} else if (type.equals(java.sql.Timestamp.class)) {
////				r.addParameter(new SqlParameter(SqlType.TIMESTAMP, null));
////			} else if (type.equals(java.sql.Time.class)) {
////				r.addParameter(new SqlParameter(SqlType.TIME, null));
////			} else if (type.equals(Double.class)) {
////				r.addParameter(new SqlParameter(SqlType.DOUBLE, null));
////			} else if (type.equals(java.sql.Date.class)) {
////				r.addParameter(new SqlParameter(SqlType.DATE, null));
////			} else { // ...
////				r.addParameter(new SqlParameter(SqlType.NUMERIC, null));
////			}
////		}
////	}
////
////	/**
////	 * 根据主键删除记录
////	 * 
////	 * @param pk
////	 *            主键
////	 * @return 影响记录数
////	 * @throws DBOperatorException
////	 */
////	public int deleteByPrimaryKey(Object pk) throws DBOperatorException {
////		if (this.primaryKeyName == null) {
////			throw new com.beetle.framework.AppRuntimeException(
////					"此表没有定义主键或为组合主键，不支持此方法");
////		}
////		UpdateOperator update = new UpdateOperator();
////		update.setDataSourceName(this.dataSourceName);
////		update.setSql(SqlGenerator.generateDeleteByPKSql(this.tableName,
////				this.primaryKeyName));
////		update.addParameter(pk);
////		try {
////			update.access();
////			return update.getEffectCounts();
////		} catch (DBOperatorException ex) {
////			throw new DBOperatorException(ex);
////		}
////	}
////
////	/**
////	 * 自动填充一行（将sql返回的字段值与其对应的值对象自动匹配起来）
////	 * 
////	 * @param rs
////	 *            RsDataSet
////	 * @return Object
////	 */
////	public Object autoRowFill(RsDataSet rs) {
////		Object o = rowToObj(rs);
////		rs.clearAll();
////		return o;
////	}
////
////	/**
////	 * 自动填充所有的结果
////	 * 
////	 * @param rs
////	 *            查询结果集－RsDataSet
////	 * @return List
////	 */
////	public List autoAllFill(RsDataSet rs) {
////		List l = new ArrayList(rs.rowCount);
////		for (int ii = 0; ii < rs.rowCount; ii++) {
////			Object o = rowToObj(rs);
////			l.add(o);
////			rs.next();
////		}
////		rs.clearAll();
////		return l;
////	}
////
////	/**
////	 * 根据主键批量删除
////	 * 
////	 * @param pks
////	 *            List
////	 * @throws DBOperatorException
////	 */
////	public int[] deleteBatchByPrimaryKey(List pks) throws DBOperatorException {
////		if (this.primaryKeyName == null) {
////			throw new com.beetle.framework.AppRuntimeException(
////					"此表没有定义主键或为组合主键，不支持此方法");
////		}
////		UpdateOperator update = new UpdateOperator();
////		update.setDataSourceName(this.dataSourceName);
////		update.setSql(SqlGenerator.generateDeleteByPKSql(this.tableName,
////				this.primaryKeyName));
////		for (int i = 0; i < pks.size(); i++) {
////			Object pk = pks.get(i);
////			SqlParameterSet r = new SqlParameterSet();
////			SqlParameter p = new SqlParameter(pk);
////			r.addParameter(p);
////			update.addBatchParameter(r);
////		}
////		try {
////			update.access();
////			return update.getBatchEffectCounts();
////		} catch (DBOperatorException ex) {
////			throw new DBOperatorException(ex);
////		} finally {
////			pks.clear();
////		}
////	}
////
////	/**
////	 * 更新记录
////	 * 
////	 * @param valueObject
////	 *            Object
////	 * @return 操作影响记录数
////	 * @throws DBOperatorException
////	 */
////	public int update(Object valueObject) throws DBOperatorException {
////		if (this.primaryKeyName == null) {
////			throw new com.beetle.framework.AppRuntimeException(
////					"此表没有定义主键或为组合主键，不支持此方法");
////		}
////		Map valueMap = objToMap(valueObject, this.filedSet);
////		UpdateOperator update = new UpdateOperator();
////		update.setDataSourceName(this.dataSourceName);
////		update.setSql(SqlGenerator.generateUpdateByPKSql(this.filedSet,
////				this.tableName, this.primaryKeyName, this.autoGenerateKey,
////				this.autoKeyFiledName));
////		Iterator it = this.filedSet.iterator();
////		Object pkValue = null;
////		while (it.hasNext()) {
////			Object key = it.next();
////			ValueInfo vi = (ValueInfo) valueMap.get(key);
////			if (key.equals(this.primaryKeyName)) {
////				pkValue = vi.getValue();
////				if (this.autoGenerateKey) {
////					continue;
////				}
////			}
////			// update.addParameter(o);
////			addUpdateParams(valueMap, update, key);
////		}
////		update.addParameter(pkValue);
////		try {
////			update.access();
////			return update.getEffectCounts();
////		} catch (DBOperatorException ex) {
////			throw new DBOperatorException(ex);
////		} finally {
////			valueMap.clear();
////		}
////	}
////
////	/**
////	 * 批量更新记录
////	 * 
////	 * @param valueObjectList
////	 *            List
////	 * @return int[]
////	 * @throws DBOperatorException
////	 */
////	public int[] updateBatch(List valueObjectList) throws DBOperatorException {
////		if (this.primaryKeyName == null) {
////			throw new com.beetle.framework.AppRuntimeException(
////					"此表没有定义主键或为组合主键，不支持此方法");
////		}
////		UpdateOperator update = new UpdateOperator();
////		update.setDataSourceName(this.dataSourceName);
////		update.setSql(SqlGenerator.generateUpdateByPKSql(this.filedSet,
////				this.tableName, this.primaryKeyName, this.autoGenerateKey,
////				this.autoKeyFiledName));
////		for (int i = 0; i < valueObjectList.size(); i++) {
////			Object valueObject = valueObjectList.get(i);
////			SqlParameterSet r = new SqlParameterSet();
////			Map valueMap = objToMap(valueObject, this.filedSet);
////			Iterator it = this.filedSet.iterator();
////			Object pkValue = null;
////			while (it.hasNext()) {
////				Object key = it.next();
////				ValueInfo vi = (ValueInfo) valueMap.get(key);
////				if (key.equals(this.primaryKeyName)) {
////					pkValue = vi.getValue();
////					if (this.autoGenerateKey) {
////						continue;
////					}
////				}
////				addBatchParams(r, valueMap, key); //
////			}
////			r.addParameter(pkValue);
////			update.addBatchParameter(r);
////			valueMap.clear();
////		}
////		try {
////			update.access();
////			return update.getBatchEffectCounts();
////		} catch (DBOperatorException ex) {
////			throw new DBOperatorException(ex);
////		} finally {
////			// valueObjectList.clear();
////		}
////	}
////
////	/**
////	 * 生成此表字段名字符串
////	 * 
////	 * @return String
////	 */
////	public String generateFieldsString() {
////		return SqlGenerator.generateFieldsFormatStr(this.filedSet);
////	}
////
////	/**
////	 * 此表是否为自动生成id
////	 * 
////	 * @return boolean
////	 */
////	public boolean isAutoGenerateKey() {
////		return autoGenerateKey;
////	}
////
////	/**
////	 * 获取表名
////	 * 
////	 * @return String
////	 */
////	public String getTableName() {
////		return this.tableName;
////	}
////
////	/**
////	 * 获取主键名称
////	 * 
////	 * @return String
////	 */
////	public String getPrimaryKeyFieldName() {
////		return this.primaryKeyName;
////	}
//
//
//}
